package dao;

import utils.DBHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserLoginDao {

    public Map<String ,Object> userLogin(String username, String pwd){
        Map<String ,Object> map=new HashMap<>();
        String sql=" select * from users where username= ? and password = ?";
        return DBHelper.selectOneMap(sql, username, pwd);
    }
    public Map<String,Object> queryid(String username){
        String sql="select id from users where username = ?";
        return  DBHelper.selectOneMap(sql,username);
    }
    public Map<String ,Object> querypwd(Integer uid){
        String sql =" select password from users where id = ?";
        return DBHelper.selectOneMap(sql,uid);
    }

    //查找用户是否存在
    public int exists(String username, String email){
        String sql = "select username from users where username = ? and email = ?";
        Map<String, Object> map = DBHelper.selectOneMap(sql, username, email);
        if (map == null){
            return 0;
        }
        return 1;
    }

    // 修改密码
    public void modify(String username, String password, String email){
        String sql = " update users set password=? where username = ? and email like ?";
        DBHelper.update(sql, password, username, "%" + email + "%");
    }

    // 查找用户默认地址信息
    public Map<String, Object> userAddress(String uid){
        String sql = "select a.`name`, a.telphone, a.site from address a, users u where u.aid = a.id and u.id = ? ";
        return DBHelper.selectOneMap(sql, uid);
    }

}
